#pragma once
#include "InputLine.h"

using namespace std;

const string BLANKS= " \n\t";
const string DELIMITERS = "()[]{};<>=+-*&";
const string BLANKS_AND_DELIMITERS = BLANKS + DELIMITERS;
Token EOFToken;

InputLine::InputLine(){
}
InputLine::~InputLine(){

}

// getLine gets a string terminated by \n and adds strings to the tokens vector
void InputLine::getLine(std::queue<Token *>& tokens, const std::string& line, int lineNum) const{
	int from = 0;
	int to = 0;
	string subLine = line;
	while (true){
		from = 0;
		to = 0;

		// skip leading blanks
		from = subLine.find_first_not_of(BLANKS);
		if (from == string::npos) break;

		// if there is a delimiter parse it right away
		if (subLine.find_first_of(DELIMITERS, from) == from){
			to = from+1;
		}
		else {
			// find where the substring ends by a use of a delimiter/blank
			to = subLine.find_first_of(BLANKS_AND_DELIMITERS, from);
			if (to == string::npos) {
				to = subLine.size();
			}
		}
		// cut the substring and add it as a Token to the vector
		string val = subLine.substr(from, to-from);
		Token * tokenPtr = new Token(lineNum, val);
		tokens.push(tokenPtr);
		
		subLine = subLine.substr(to);
	}
}

